/**
 * Created by liubin on 2017/6/2.
 */



var PdkJoinFreeResponsepdk = function(){
    var that = new GameResponseBase();

    that.handle = function (binary, msgid) {
        that.loadMessage(binary, msgid);
        mo.closeWaitLayer();

        var code = that.msg.code;

        //代开房
        if (code == 0 && that.msg.min_coins != null && that.msg.min_coins != 0){
            mo.showMsgDialogOkAndCancel("为好友代开房成功！\n房间号:" + that.msg.min_coins, function(){
                mo.eventHelper.dispatch("showRoomYilaiLayer");
            }, mo.sceneMainLayer, function(){

            }, mo.sceneMainLayer);
            return;
        }

        if (code == 0){
            //进入牌桌
            mo.sceneHelper.runScenePdk();
            mo.pdkTable.loadPlayCard();

            //牌桌密码
            var tablePassWord = that.msg.TablePassWord;

            //包房名称
            var GroupName = that.msg.GroupName;

            //游戏设置
            mo.pdkTable.setPdkConfig(that.msg.CfgJson, tablePassWord, GroupName);

            //创建者
            mo.pdkTable.mIsRoomCreator = (that.msg.CreateUid == mo.gameUserInfo.uid);

            //是否是代开
            mo.pdkTable.setShowRoomCreate(that.msg.CreateUser);

            //短线重连重新绘制牌桌
            var game_stats = that.msg.game_stats;
            if (game_stats != null){
                //得到上局结果
                mo.pdkTableStatus.setReconnectStatus(game_stats);
            }

        }else if (code == 2){
            mo.showRoomMsgShow("抱歉，您代开房的房间数量已达到上限");
        }else if (code == 3){
            mo.showRoomMsgShow("该局已经开始，不能加入");
        }else if (code == 5){
            mo.showRoomMsgShow("加入牌局失败，牌桌号不存在");
        }else if (code == 8){
            mo.showRoomMsgShow("创建牌局失败，包房卡不足");
        }else if (code == 6){
            mo.showRoomMsgShow("加入牌局失败，密码错误");
            mo.eventHelper.dispatch("JoinFreeResponse_error_code6");
        }else if (code == 7) {
            //other
            mo.showRoomMsgShow("加入牌局失败，号码错误或者房间人数已满");
        }else {
            mo.showRoomMsgShow("error code=" + code);
        }

        //通知加入房间结果
        mo.eventHelper.dispatch_1("msg_joinFreeTableStatus", code == 0);

        //关闭等待
        mo.eventHelper.dispatch("closeWaitCreateTableLayer");
    };

    return that;
};